
import { DefaultLayout, GraphNode } from "@/js/components/GraphNode"
import { GraphView } from "@/js/components/GraphView"
import { InputLinkNodeAny, InputLinkNodeBoolean, InputLinkNodeFlow } from "@/js/components/InputLinkNode"

export class CastToBoolean extends GraphNode{
    layout?: DefaultLayout
    load(){
        super.load()

        const layout = new this.DefaultLayout(this, this.graphView as GraphView,false,false)
        this.layout = layout
        this.appendChild(layout.container)

        const booleanEntry = new InputLinkNodeAny(this, this.graphView as GraphView, {
            name: "boolean",
            model: "entry",
            showDesc: false,
            showInput: false
        })
        layout.main?.left.appendChild(booleanEntry)

        layout.main?.right.appendChild(new InputLinkNodeBoolean(this, this.graphView as GraphView, {
            name: "boolean", 
            model: "output",
            showDesc: false,
            showInput: false,
            linkMaxCount: 100000
        }))
    }

}

CastToBoolean.parser =  ({node,toNode}: any) => {
    return '!!' + toNode(node.enters.boolean[0], 'output') || 'false'
}